<?php 
namespace Home\Controller;
use Think\Controller;

class RegisterController extends Controller{

	public function Register(){
	 
		 
	if($_POST){
		$yzm = $_POST['yzm'];
			$verify = new \Think\Verify();  
			$result = $verify->check($yzm);

			if($result){
				if($_POST['username']){
				$user = D('User');
				$name = $_POST['username'];

				$result = $user->query("select id from user where username='{$name}'");
				if ($result){
					$this->error("该用户名已被注册！");
				}else{
					$data['username'] = $_POST['username'];
					$data['pass'] = md5($_POST['pass']);
					$data['addtime'] = time();
					$user->add($data);
					$this->redirect('success');
				}
			}else{
				$this->error("用户名不能为空！");
			}

			}else{
				$this->error('验证码错误！');
			}
			
		}else{
			$this->display();
	}
        
		
	}

	public function yzm(){

		$config =    array(  
		  'fontSize'    =>    50,    // 验证码字体大小   
		  'length'      =>    4,     // 验证码位数    
		  'useNoise'    =>    false, // 关闭验证码杂点
		  
		 );
		$Verify = new \Think\Verify($config);
		$Verify->entry();
	}


	public function yanzheng(){
	    $name = $_GET['username'];
	    $user = D('User');
	    //echo $name;die();
	    $result = $user->where('username='.'"'.$name.'"')->select();
	    
	    if($result){
	      echo 1;
	    }
	  }
	
	}

	

?>
